<template>
  <div>
    <ScholarshipStudentView v-if="isStudent" />
    <ScholarshipStaffView v-else />
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue'
import ScholarshipStudentView from '@/views/Scholarship/ScholarshipStudentView.vue'
import ScholarshipStaffView from '@/views/Scholarship/ScholarshipStaffView.vue'
const isStudent = ref(false)

onMounted(() => {
  const userInfoRaw = localStorage.getItem('userInfo')
  if (userInfoRaw) {
    try {
      const userInfo = JSON.parse(userInfoRaw)
      const roleId = Number(userInfo?.roleId)
      isStudent.value = roleId === 4
    } catch (_) {
      const storedUserType = localStorage.getItem('userType')
      isStudent.value = storedUserType === 'student'
    }
  } else {
    const storedUserType = localStorage.getItem('userType')
    isStudent.value = storedUserType === 'student'
  }
})
</script>
